# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=avahi
pkgver=0.8
pkgrel=17
pkgdesc="multicast/unicast DNS-SD framework"
url="https://www.avahi.org/"
arch="all"
license="LGPL-2.1-or-later"
pkgusers="avahi"
pkggroups="avahi"
depends_openrc="dbus"
depends_dev="gdbm-dev"
makedepends="
	$depends_dev
	autoconf
	automake
	dbus-dev
	expat-dev
	gettext-dev
	glib-dev
	gobject-introspection-dev
	libcap-dev
	libdaemon-dev
	libevent-dev
	libtool
	py3-dbus
	py3-gobject3-dev
	py3-setuptools
	python3-dev
	python3-gdbm
	xz
	"
install="$pkgname.pre-install"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-tools
	$pkgname-glib
	$pkgname-libs
	py3-avahi:py3
	$pkgname-compat-howl:howl
	$pkgname-compat-libdns_sd:lidns_sd
	$pkgname-lang
	$pkgname-openrc
	"
source="https://github.com/lathiat/avahi/releases/download/v$pkgver/avahi-$pkgver.tar.gz
	CVE-2021-3468.patch
	CVE-2021-3502.patch
	CVE-2023-1981.patch
	CVE-2023-38469.patch
	CVE-2023-38470.patch
	CVE-2023-38471.patch
	CVE-2023-38472.patch
	CVE-2023-38473.patch
	Fetch-build-db-from-upstream-git.patch
	build-db-Use-the-same-database-format-that-the-C-code-exp.patch
	"

# secfixes:
#   0.8-r16:
#     - CVE-2023-38470
#   0.8-r15:
#     - CVE-2023-38469
#     - CVE-2023-38471
#   0.8-r14:
#     - CVE-2023-1981
#     - CVE-2023-38472
#     - CVE-2023-38473
#   0.8-r5:
#     - CVE-2021-3502
#   0.8-r4:
#     - CVE-2021-3468
#   0.7-r2:
#     - CVE-2017-6519
#     - CVE-2018-1000845
#   0:
#     - CVE-2021-26720

prepare() {
	default_prepare
	autoreconf -vif
}

build() {
	# we dont build autoipd since dhcpcd does same job
	LDFLAGS="$LDFLAGS -lintl" \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--disable-autoipd \
		--disable-qt3 \
		--disable-qt4 \
		--disable-qt5 \
		--disable-gtk \
		--disable-gtk3 \
		--disable-mono \
		--disable-monodoc \
		--disable-doxygen-doc \
		--disable-xmltoman \
		--enable-compat-libdns_sd \
		--enable-compat-howl \
		--enable-python \
		--with-dbus-sys=/usr/share/dbus-1/system.d \
		--with-distro="gentoo"
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install

	install -d -o avahi -g avahi "$pkgdir"/var/run/avahi-daemon

	ln -s avahi-compat-howl.pc "$pkgdir"/usr/lib/pkgconfig/howl.pc
	ln -s avahi-compat-libdns_sd.pc "$pkgdir"/usr/lib/pkgconfig/libdns_sd.pc
	ln -s avahi-compat-libdns_sd/dns_sd.h "$pkgdir"/usr/include/

	# XXX these are added since the python support, but are broken
	rm -v "$pkgdir"/usr/bin/avahi-bookmarks
	rm -v "$pkgdir"/usr/bin/avahi-discover
	rm -v "$pkgdir"/usr/share/applications/avahi-discover.desktop
	rmdir -p "$pkgdir"/usr/share/applications/ || true

	# can't install tmpfs
	rm -r "$pkgdir"/var/run
}

tools() {
	pkgdesc="Command line tools for mDNS browsing and publishing"

	amove \
		usr/bin/avahi-browse* \
		usr/bin/avahi-publish* \
		usr/bin/avahi-resolve* \
		usr/bin/avahi-set*
}

glib() {
	pkgdesc="Glib libraries and GObject wrapper for avahi"

	amove usr/lib/libavahi-glib.so.* \
		usr/lib/libavahi-gobject.so.*
}

libs() {
	pkgdesc="Libraries for avahi run-time use"

	amove usr/lib/libavahi-common.so.* \
		usr/lib/libavahi-client.so.*
}

howl() {
	pkgdesc="Libraries for howl compatibility"

	amove usr/lib/libhowl.so.*
}

lidns_sd() {
	pkgdesc="Libraries for Apple Bonjour mDNSResponder compatibility"

	amove usr/lib/libdns_sd.so.*
}

py3() {
	pkgdesc="Python Avahi module"
	depends="py3-dbus python3"

	amove usr/lib/python*
}

sha512sums="
c6ba76feb6e92f70289f94b3bf12e5f5c66c11628ce0aeb3cadfb72c13a5d1a9bd56d71bdf3072627a76cd103b9b056d9131aa49ffe11fa334c24ab3b596c7de  avahi-0.8.tar.gz
743430a532b8ec246672cd0997b7831efc15c461cbfe0461faac5d6525293297efb7c06f759b2bcd71d1842ba165464fd334508534e6c247211d613061c49da5  CVE-2021-3468.patch
9e4688ffd8e512c0f614fd24fff2a2a1c66e009069229a6f81dcd382edfff5a8635e0551533c7f9271973a87e62e199fdb34a5560dab27c0a328f531c94f757d  CVE-2021-3502.patch
6be9c7bdeb98828c55069b4570dd6ac87354ed59df6445683ed78a26e40fad194dbb745a5df32b0fc7abb9a393e655334a31833db996ccb39e71d8a801adea6a  CVE-2023-1981.patch
7ebaa7220c72c8bc16d34fad54dc4dd173541e5e97f066b53b8c6e9af01a5e910eab1db998d34708af86a92329c65aa3a398f16279a7204117afd84362a3100c  CVE-2023-38469.patch
ea593c570ea7ce133ef4e47a5557b4b1dccdd45bba87bd1e948409c7abdb394eeea2d2cda2bf2f5b720b2c3cf41aee2b6bb189b55b842077024aaf7947e1a3c6  CVE-2023-38470.patch
b69d63a0490447e3aa2c9f0179d9b76d49fb5d9cce6b02459c1ef561379217c9157790938def9775527c1109e21e99970434eb56ca61337b2c3df1c5a79ab5a1  CVE-2023-38471.patch
98e141a8f17303a235b926dda452f4b9671e11395ea70e4a7e2ea8c446fb52a84796de273fcc08c556c8b3895cf703b58e5ccc7dc15b3da4c28aa0f9ebaaa2b0  CVE-2023-38472.patch
66f40c5ed8e771530c381c7c32ba47562b372b48a41af5aa3b972e350b77afac521934e2fc0d2122b1456f331920dd74bd9846d5efca39b9e3db7e47711e3695  CVE-2023-38473.patch
302db5f4c8339b7f074aa4b2f2e8108e33e128db26f10a201a63bd09f9c2bde600929e586e00d7f7c448019eefbc3e97eb8b419079253f5f4fb60e477a577fa1  Fetch-build-db-from-upstream-git.patch
e4e923dbaa0c729a8685b71f1487f337fd7c68b464b04643127a2f7a3a34b24f87869c9c185632229b25f350425ea979ddb329eda043548d55ae86f5c905dd11  build-db-Use-the-same-database-format-that-the-C-code-exp.patch
"
